﻿namespace EFS.RC.CC.CH.Tables
{
	public static class SurveySessionAnswers
	{
		/// Returns an object from a data row
		public static EFS.RC.CC.CH.Entities.Surveys.Sessions.Answer FromTableRow(System.Data.DataRow row)
		{
			// check
			EFS.Common.Verify.Reference(row, "row");

			// create new
			EFS.RC.CC.CH.Entities.Surveys.Sessions.Answer dataObj = new EFS.RC.CC.CH.Entities.Surveys.Sessions.Answer();

			// ID
			dataObj.ID = EFS.DB.DataRow.Int32(row, "ID");

			// SURVEY_SESSION_ID
			dataObj.SurveySessionId = EFS.DB.DataRow.Int32(row, "SURVEY_SESSION_ID");

			// SURVEY_ANSWER_ID
			dataObj.SurveyAnswerId = EFS.DB.DataRow.Int32(row, "SURVEY_ANSWER_ID");

			// COMMENT
			dataObj.Comment = EFS.DB.DataRow.String(row, "COMMENT");

			// ok
			return dataObj;
		}

		/// Create
		public static System.Int32? Create(
			System.Int32 surveySessionId,
			System.Int32 surveyAnswerId,
			System.String comment,
			EFS.DB.Connection connection)
		{
			// make params
			EFS.DB.Parameters.Array parametersArray = new EFS.DB.Parameters.Array(
				new System.String[] { "survey_session_id", "survey_answer_id", "comment", "id" },
				new System.Object[] { surveySessionId, surveyAnswerId, comment, default(System.Int32) },
				new System.Boolean[] { false, false, false, true });

			// exec create
			connection.DoExecuteNonQuery("[dbo].[SurveySessionAnswers_Create]", parametersArray);

			// get id value
			return parametersArray.GetOutPrameterValue<System.Int32?>("id"); 
		}

		/// Create
		public static void Update(
			System.Int32 surveyAnswerId,
			System.String comment,
			System.Int32 surveySessionAnswerId,
			EFS.DB.Connection connection)
		{
			// make params
			EFS.DB.Parameters.Array parametersArray = new EFS.DB.Parameters.Array(
				new System.String[] { "survey_answer_id", "comment", "id" },
				new System.Object[] { surveyAnswerId, comment, surveySessionAnswerId },
				new System.Boolean[] { false, false, false });

			// exec create
			connection.DoExecuteNonQuery("[dbo].[SurveySessionAnswers_Update]", parametersArray);

		}
	}

}